//
//  UIView+ShowText.m
//  德方军考通
//
//  Created by 毕武侠 on 16/8/27.
//  Copyright © 2016年 毕武侠. All rights reserved.
//

#import "UIView+ShowText.h"
#import <UIImage+GIF.h>
//#import "UIImage+Category.h"

@implementation UIView (ShowText)

// 自己添加的提醒界面
+ (void)showTextOnly:(UIView *)view message:(NSString *)message {
    [self showTextOnly:view message:message delay:1.6 completionBlock:nil];
}

+ (void)showTextOnly:(UIView *)view message:(NSString *)message delay:(CGFloat)delay {
    [self showTextOnly:view message:message delay:delay completionBlock:nil];
}

+ (void)showTextOnly:(UIView *)view
             message:(NSString *)message
     completionBlock:(MBProgressHUDCompletionBlock) completionBlock {
    [self showTextOnly:view message:message delay:1.6 completionBlock:completionBlock];
}

+ (void)showTextOnly:(UIView *)view
             message:(NSString *)message
               delay:(CGFloat)delay
     completionBlock:(MBProgressHUDCompletionBlock) completionBlock {
    
    [MBProgressHUD hideHUDForView:view animated:YES];
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    // Configure for text only and offset down
    hud.mode = MBProgressHUDModeText;
    hud.label.text = message;
    hud.margin = 10.f;
    hud.label.numberOfLines = 0;
    hud.completionBlock = completionBlock;
    [hud hideAnimated:YES afterDelay:delay];
}


+ (void)showLoadingImageToView:(UIView *)view {
    [self showLoadingImageToView:view title:nil];
}

+ (void)showLoadingImageToView:(UIView *)view title:(NSString *)title {
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.mode =  MBProgressHUDModeCustomView;
    UIImageView *imageView = [[UIImageView alloc] init];
//    imageView.backgroundColor = [UIColor redColor];
//#if TGT_ZYWX
//
//    hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
//    hud.bezelView.backgroundColor = [UIColor whiteColor];
//
//    NSString *path = [[NSBundle mainBundle] pathForResource:@"loading" ofType:@"gif"];
//    NSData *data = [NSData dataWithContentsOfFile:path];
//    UIImage *image = [UIImage sd_animatedGIFWithData:data];
//    imageView.image = image;
//
//    
//#elif TGT_XMGK || TGT_XBGK
    UIImage *image = [UIImage imageNamed:@"LoadImage"];
    imageView.image = image;
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"];
    animation.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
    animation.toValue = [NSValue valueWithCATransform3D: CATransform3DMakeRotation(M_PI_2, 0.0, 0.0, 1.0) ];
    animation.duration = 0.25;
    animation.cumulative = YES;
    animation.removedOnCompletion = NO;
    animation.fillMode = kCAFillModeForwards;
    animation.repeatCount = MAXFLOAT;
    [imageView.layer addAnimation:animation forKey:@"LoadingImageViewKey"];
    
//#endif
    
    hud.customView = imageView;
    hud.label.text = title;
    hud.offset = CGPointMake(0, -24);
    hud.removeFromSuperViewOnHide = YES;
    [hud showAnimated:YES];
}


@end
